package com.pw.study.mr.letter;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class ReducerByLetter extends Reducer<Text, IntWritable, Text,IntWritable> {
    private Text rk = new Text();
    private IntWritable rv = new IntWritable();
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        System.out.println("context  "+context.toString());
        Iterator<IntWritable> it = values.iterator();
        int sum =0;
        while(it.hasNext()){
            sum += it.next().get();
        }
        rk.set(key);
        rv.set(sum);
        context.write(rk,rv);
    }
}
